package org.linlinjava.litemall.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminShopId;
import org.linlinjava.litemall.admin.service.AdminLumiereFormulaService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LumiereFormula;
import org.linlinjava.litemall.db.domain.LumiereGoodsFormulaCorrelation;
import org.springframework.web.bind.annotation.*;


@Api(tags = "配方管理API")
@RestController
@RequestMapping("admin/formula")
@RequiredArgsConstructor
public class AdminLumiereFormulaController {

    private final AdminLumiereFormulaService adminLumiereFormulaService;

    @ApiOperation("配方管理-查询配方列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "formulaName",value = "配方名称")
    })
    @LogAnno
    @GetMapping("/list")
    public ResponseUtil.Response list(LumiereFormula lumiereFormula,
                                      @RequestParam("limit")Integer limit,
                                      @RequestParam("page")Integer page) {
        return adminLumiereFormulaService.listLumiereFormula(lumiereFormula,page,limit);
    }

    @ApiOperation("配方管理-查询配方列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "formulaName",value = "配方名称")
    })
    @LogAnno
    @GetMapping("/list-all")
    public ResponseUtil.Response listAll(LumiereFormula lumiereFormula,@RequestParam("limit")Integer limit,
                                         @RequestParam("page")Integer page) {
        return adminLumiereFormulaService.listAllLumiereFormula(lumiereFormula,page,limit);
    }

    @ApiOperation("配方管理-复制配方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
    })
    @LogAnno
    @GetMapping("/copy")
    public ResponseUtil.Response copy(Integer id)  {
        return adminLumiereFormulaService.copyLumiereFormula(id);
    }

    @ApiOperation("配方管理-新增配方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formulaName",value = "配方名称"),
            @ApiImplicitParam(name = "formulaTypeId",value = "配方类型"),
            @ApiImplicitParam(name = "formulaRemark",value = "配方备注"),
    })
    @LogAnno
    @PostMapping("/add")
    public ResponseUtil.Response add(LumiereFormula lumiereFormula)  {
        return adminLumiereFormulaService.addLumiereFormula(lumiereFormula);
    }

    @ApiOperation("配方管理-编辑配方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formulaName",value = "配方名称"),
            @ApiImplicitParam(name = "formulaTypeId",value = "配方类型"),
            @ApiImplicitParam(name = "formulaRemark",value = "配方备注"),
    })
    @LogAnno
    @PutMapping ("/update")
    public ResponseUtil.Response update(LumiereFormula lumiereFormula)  {
        return adminLumiereFormulaService.updateLumiereFormula(lumiereFormula);
    }

    @ApiOperation("配方管理-删除配方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
    })
    @LogAnno
    @DeleteMapping("/delete")
    public ResponseUtil.Response delete(Integer id)  {
        return adminLumiereFormulaService.deleteLumiereFormula(id);
    }

    @ApiOperation("配方管理-添加商品配方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
            @ApiImplicitParam(name = "goodsId",value = "商品id"),
            @ApiImplicitParam(name = "formulaId",value = "配方id"),
    })
    @LogAnno
    @PostMapping("/addGoodsFormulaCorrelation")
    public ResponseUtil.Response addGoodsFormulaCorrelation(LumiereGoodsFormulaCorrelation lumiereGoodsFormulaCorrelation){
        return adminLumiereFormulaService.addLumiereGoodsFormulaCorrelation(lumiereGoodsFormulaCorrelation);
    }

    @ApiOperation("配方管理-解除绑定商品配方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
            @ApiImplicitParam(name = "goodsId",value = "商品id"),
            @ApiImplicitParam(name = "formulaId",value = "配方id"),
    })
    @LogAnno
    @PostMapping("/unbundleGoodsFormulaCorrelation")
    public ResponseUtil.Response unbundleGoodsFormulaCorrelation(LumiereGoodsFormulaCorrelation lumiereGoodsFormulaCorrelation){
        return adminLumiereFormulaService.unbundleLumiereGoodsFormulaCorrelation(lumiereGoodsFormulaCorrelation);
    }

    @ApiOperation("配方管理-通过商品查询配方")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId",value = "商品id"),
    })
    @LogAnno
    @GetMapping("/listGoodsFormulaSpecifications")
    public ResponseUtil.Response listGoodsFormulaSpecifications(@RequestParam("goodsId")Integer goodsId){
        return adminLumiereFormulaService.getGoodsFormulaSpecifications(goodsId);
    }

    @ApiOperation("配方管理-查询商品配方关联表的配方详细数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId",value = "商品id"),
    })
    @LogAnno
    @GetMapping("/getGoodsFormulaCorrelationDetails")
    public ResponseUtil.Response getGoodsFormulaCorrelationDetails(@RequestParam("goodsId")Integer goodsId) {
        return adminLumiereFormulaService.getGoodsFormulaCorrelationDetails(goodsId);
    }


}
